<template>
	<view class="main" :style="{ '--color': vuex_config.adminTheme, '--price': vuex_config.adminPrice }">
		<view class="main_item"  v-for="(item, index) in dataForm.detailed" :key="index">
			<view class="title_box">
				<view class="bor">
					<view class="no_l">订单编号：{{ dataForm.order_no }}</view>
				</view>
			</view>
			<view class="prod_item">
				<view class="prod_img">
					<image :src="formatPictureImg(item.product_img)"></image>
				</view>
				<view class="prod_cont">
					<view class="name_main">
						<view class="prod_name u-line-2">{{ item.name }}</view>
						<view class="prod_stand">
							<view class="stand_name">
								<text v-if="item.name">商品属性：{{ item.name }}</text>
							</view>
							<view class="buy_num">x{{ item.num }}</view>
						</view>
					</view>
					<view class="prod_bot">
						<view class="prce_box">
							<view class="price_sign">￥</view>
							<view class="price_num">{{ item.price }}</view>
						</view>
						<view class="valit_main">
							<view class="surplus">未核销：{{item.num-item.validate_num}}</view>
							<u-number-box :input-width="44" v-model="item.verifiNum" :max="item.num - item.validate_num"></u-number-box>
						</view>
					</view>
				</view>
			</view>
			<view class="btn" :class="[item.num == item.validate_num?'disabled':'use']" @click="startWrite(item)">{{item.num == item.validate_num?'已核销':'立即核销'}}</view>
		</view>
		<view class="main_item">
			<view class="title_box">
				<view class="bor">
					<view class="title">用户信息</view>
				</view>
			</view>
			<view class="cell_box">
				<view class="cell_item">
					<view class="cell_l">联系人：</view>
					<view class="cell_r">{{ dataForm.name }}</view>
				</view>
				<view class="cell_item">
					<view class="cell_l">手机号：</view>
					<view class="cell_r">{{ dataForm.mobile }}</view>
				</view>
				<view class="cell_item">
					<view class="cell_l">下单时间：</view>
					<view class="cell_r">{{ dataForm.date_creation | formTime() }}</view>
				</view>
				<view class="cell_item">
					<view class="cell_l">备注：</view>
					<view class="cell_r">{{ dataForm.remark? dataForm.remark:'无'}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		formatDate
	} from '@/utils/moment/index.js';
	import {
		adminPost
	} from '@/common/http.request.js';
	export default {
		components: {},
		data() {
			return {
				dataForm: {}
			};
		},
		onLoad(options) {
			if (options && options.order_no) {
				this.initPage(options.order_no, options.type);
			}
		},
		filters: {
			formTime(val) {
				return formatDate(val, 'YYYY-MM-DD HH:mm:ss');
			}
		},
		methods: {
			initPage(order_no, orderType) {
				this.$loading();
				adminPost('GetWriteOFFOrderList', {
					order_no: order_no || this.dataForm.order_no,
					business_id: this.vuex_business.pk_id,
				}).then(({
					data
				}) => {
					this.dataForm = data[0]
					this.dataForm.detailed.forEach(item=>{
						item.verifiNum = 0
					})
					this.$hide();
				});
			},
			// 核销
			startWrite(item) {
				if(item.num == item.validate_num) return this.$toast('已完成核销')
				if(item.verifiNum =='0')return this.$toast('核销数量不能为空')
				adminPost('SetWriteOFFOrder',{order_id:this.dataForm.pk_id,detailed_id:item.pk_id,detailed_num:item.verifiNum},{headerMethod:'json'}).then(res=>{
					this.uniBack(1)
				})
			}
		}
	};
</script>
<style lang="scss">
	page {
		background-color: $www-theme-bg;
	}
</style>
<style scoped lang="scss">
	.main {
		padding: 20rpx 0 20rpx;
	}

	.main_item {
		background-color: #fff;
		border-radius: 10rpx;
		overflow: hidden;
		margin: 0 20rpx;
		margin-bottom: 24rpx;

		.title_box {
			padding: 0 20rpx;

			.bor {
				font-size: 30rpx;
				height: 78rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1px solid #f5f5f5;
			}

			.no_l {
				font-size: 30rpx;
			}

			.no_r {
				font-size: 30rpx;
				color: var(--color);
			}

			.title {
				font-weight: bold;
				font-size: 30rpx;
			}
		}
	}

	.prod_item {
		padding: 20rpx;
		display: flex;
		align-items: center;

		.prod_img {
			width: 180rpx;
			height: 180rpx;
			margin-right: 14rpx;
			border-radius: 10rpx;
			overflow: hidden;
		}

		.prod_cont {
			flex: 1;
			overflow: hidden;
			padding: 4rpx 0;
			height: 180rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.prod_name {
				line-height: 36rpx;
			}

			.prod_stand {
				display: flex;
				line-height: 32rpx;
				height: 32rpx;
				margin-top: 14rpx;

				.stand_name {
					flex: 1;
					overflow: hidden;
					font-size: 26rpx;
					color: #999;
				}

				.buy_num {
					font-size: 28rpx;
				}
			}

			.prod_bot {
				display: flex;
				align-items: center;

				.prce_box {
					color: #999999;
					flex: 1;
					overflow: hidden;

					.price_sign {
						display: inline-block;
						font-size: 24rpx;
					}

					.price_num {
						display: inline-block;
						font-weight: bold;
						font-size: 30rpx;
					}
				}

				.valit_main {
					display: flex;
					align-items: center;

					.surplus {
						color: var(--color);
						margin-right: 12rpx;
					}
				}
			}
		}
	}

	.btn {
		height: 72rpx;
		line-height: 72rpx;
		text-align: center;
		color: #fff;

		&.disabled {
			background-color: #cccccc;
		}
		&.use{
			background-color: var(--color);
		}
	}

	.cell_box {
		padding: 20rpx 20rpx 0;

		.cell_item {
			display: flex;
			line-height: 40rpx;
			padding-bottom: 20rpx;

			.cell_l {
				margin-right: 14rpx;
			}

			.cell_r,
			.cell_label {
				flex: 1;
				overflow: hidden;
				text-align: right;
			}

			.cell_r {
				color: #999;

				.r_box {
					text-align: left;
					display: inline-block;
				}
			}
		}
	}
</style>
